/**
 * 数据源列表视图类
 * */
var numStore = new Ext.data.SimpleStore
({
    fields: ["id", "pageSize"],
    data: [
        ['5', 5],
        ['10', 10],
        ['20', 20],
        ['50', 50]
    ]
});
var statStore = new Ext.data.SimpleStore
({
    fields: ["id", "text"],
    data: [
        ['0', '禁用'],
        ['1', '启用']
    ]
});
Ext.define("core.product.view.ProductGrid", {
    extend: "Ext.grid.Panel",
    alias: "widget.product_grid",
    id: 'product_grid',
    store: "core.product.store.ProductStore",
    border: 0,
    selModel: {
        selType: "checkboxmodel"
    },
    multiSelect: true,
    frame: true,
    tbar: [
        {xtype: 'button', text: '添加', ref: 'add', iconCls: 'table_add'}, '|',
        {xtype: 'button', text: '删除', ref: 'del', iconCls: 'table_remove'}, '|',
        {xtype: 'button', text: '刷新', ref: 'ref', iconCls: 'table_refresh'},
        {xtype: 'textfield', id:"gIdText", emptyText: '任务执行ID->模糊查询'}, '|',
        {xtype: 'combobox', width:80,id:"statText", emptyText: '选择状态',
            mode: 'local',
            store: statStore,
            displayField: 'text',
            valueField: 'id'}, '|',
        {xtype: 'button', text: '查询', ref: 'searchBtn', iconCls: 'grid_search'},
        {xtype: 'button', text: '重置', ref: 'resetBtn', iconCls: 'tree_delete'}, '|',
        '双击记录修改',
        "->",
        '任务执行ID筛选:',
        {
            xtype: 'triggerfield',
            triggerCls: Ext.baseCSSPrefix + 'form-search-trigger',
            listeners: {
                "change": function (_this, _new, _old, _opt) {
                    var _store = _this.ownerCt.ownerCt.getStore();
                    _store.clearFilter(false);
                    //关键字groupId
                    _store.filter("groupId", _new);
                }
            },
            onTriggerClick: function () {
                var _store = this.ownerCt.ownerCt.getStore();
                _store.clearFilter(false);
                //关键字groupId
                _store.filter("groupId", this.getValue());
            }
        }
    ],
    bbar: {
        xtype: 'pagingtoolbar',
        id: 'productPage',
        store: 'core.product.store.ProductStore',
        dock: 'bottom',
        displayInfo: true,
        items: [
            {
                xtype: 'combobox',
                width: 45,
                forceSelection: true,
                mode: 'local',
                store: numStore,
                displayField: 'id',
                valueField: 'pageSize',
                id: 'prdPageSize',
                value: 10
            }]
    },
    viewConfig: {
        enableTextSelection: true
    },
    enableKeyNav: true,  //可以使用键盘控制上下
    columnLines: true, //展示竖线
    listeners: {
        cellClick: function (thisTab, td, cellIndex, record, tr, rowIndex, event, eventObj) {
            if(this.columns[cellIndex].dataIndex == "status"){
            // if (cellIndex == 8) {//设置按钮列
                var id = record.data.id;
                var statusText = record.data.status;
                var groupId = record.data.groupId;
                Ext.Ajax.request({
                    waitMsg: '正在进行处理,请稍后...',
                    url: "batchSchedule/updateStatus.do",
                    params: {
                        id: id,
                        groupId: groupId,
                        status: statusText
                    },
                    method: "POST",
                    timeout: 10000,
                    success: function (response, opts) {
                        var resObj = Ext.decode(response.responseText);
                        if (resObj.success) {
                            var _store = record.store;
                            _store.load();
                            Ext.Msg.alert("提示", resObj.msg);
                        } else {
                            Ext.Msg.alert("提示", resObj.msg);
                        }
                    }
                });
            }
        }
    },
    columns: [
        {xtype: 'rownumberer'},
        {
            text: "ID", dataIndex: "id", width: 150, hidden: false, field: {
            xtype: "textfield"
        }
        },
        {
            text: "任务执行ID", dataIndex: "groupId", width: 150, field: {
            xtype: "textfield"
        }
        },
        {
            text: "CRON表达式", dataIndex: "cronExpression", width: 100, field: {
            xtype: "textfield"
        }
        },
        {
            text: "开始日期", dataIndex: "startTime", width: 120, renderer: function (v) {
            return v.substring(0, 10);
        }
        },
        {
            text: "结束日期", dataIndex: "stopTime", width: 120, renderer: function (v) {
            return v.substring(0, 10);
        }
        },
        // {
        //     text: "执行IP", dataIndex: "ipAddr", width: 80, field: {
        //     xtype: "textfield"
        // }
        // },
        {
            text: "执行类", dataIndex: "quartzJobClass", width: 270, field: {
            xtype: "textfield"
        }
        },
        {
            text: "当前状态", dataIndex: "status", align: "center",
            renderer: function (v, metaData, record, rowIndex, colIndex, store, view) {
                var value;
                if (v == "1") {
                    value = "<font color=white>启 用</font>";
                    metaData.style = ' margin: 1px; padding: 1px;background: orangered;';
                    metaData.tdAttr = 'data-qtip=' + "点击停用";
                    // return '<SPAN style="COLOR: palegreen">' + v + '</SPAN>';
                } else if (v == "0") {
                    value = "<font color=white>禁 用</font>";
                    metaData.style = ' margin: 1px; padding: 1px;background: green;';
                    metaData.tdAttr = 'data-qtip=' + "点击启用";
                }
                return value;
            }
        }
    ],
    initComponent: function () {
        this.callParent(arguments);
    }
});